package com.itheima.mall.commons.page;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author yan.zhou
 * @date 2022/2/5
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult implements Serializable {

    private List list;
    //当前页数
    private long pageNum;
    //页大小
    private long pageSize;
    //总条数
    private long total;
    //总页数
    //private Long pages;
    private long totalPage;


    /**
     * @param counts      总记录数
     * @param pageSize    每页显示条数
     * @param currentPage // 当前页
     * @param data        // 数据
     * @return
     */
    public static PageResult init(List data,long currentPage,long pageSize,long counts) {
        long totalPage = counts % pageSize == 0 ? counts / pageSize : counts / pageSize + 1;

        return new PageResult(data, currentPage, pageSize, counts, totalPage);
    }
}
